home *** CD-ROM | disk | FTP | other *** search
- // battery.cpp
-
-
- // includes
- #include "battery.h"
- #include "drawing.h"
- #include "Finder_res.h"
-
-
- // constants
- const UInt32 k_update_interval = 30; // seconds
-
-
- //
- // constructor
- //
- battery::battery(FormGadgetType* gadgetP, view* in_superview):
- pane(&gadgetP->rect, in_superview)
- {
- reset_idle_timer();
- }
-
- //
- // destructor
- //
- battery::~battery() {
- // do nothing
- }
-
- #pragma mark -
-
- //
- // draw_self()
- //
- void
- battery::draw_self() {
- // variables
- UInt16 battery_level, warn_threshold, critical_threshold, max_ticks;
- SysBatteryKind kind;
- Boolean plugged_in;
- unsigned char percent;
- Int16 battery_icon_number, bitmap_id;
-
- // get battery info
- battery_level = SysBatteryInfo (false, &warn_threshold, &critical_threshold, &max_ticks, &kind, &plugged_in, &percent);
-
- // we could create and use battery icons with bolts if charging, or with AC plug overlay
-
- // calculate battery icon number
- battery_icon_number = Int16(percent) / 10;
- if (battery_icon_number>9)
- battery_icon_number = 9;
- bitmap_id = Battery0Bitmap + battery_icon_number;
-
- // get battery gadget
- int x = m_bounds.topLeft.x;
- int y = m_bounds.topLeft.y;
- draw_bitmap(bitmap_id, x, y, left_align, top_align);
- }
-
-
- //
- // idle_self()
- //
- void
- battery::idle_self() {
- UInt32 now = TimGetSeconds();
-
- if (now>=m_idle_timer) {
- draw();
- reset_idle_timer();
- }
- }
-
- //
- // reset_idle_timer()
- //
- void
- battery::reset_idle_timer() {
- set_idle_timer (k_update_interval);
- }
-
- //
- // set_idle_timer()
- //
- void
- battery::set_idle_timer(UInt32 interval) {
- m_idle_timer = TimGetSeconds() + interval;
- }
-
-